from appium import webdriver


class BasePage:
    # driver实例化
    def __init__(self, driver=None):
        if driver is None:
            caps = {}
            caps["platformName"] = "android"
            caps["appium:deviceName"] = "Calculator"
            caps["appium:appActivity"] = '.Calculator'
            caps["appium:appPackage"] = "com.android.calculator2"
            caps["appium:ensureWebviewsHavePages"] = True
            caps["appium:nativeWebScreenshot"] = True
            caps["appium:newCommandTimeout"] = 3600
            caps["appium:connectHardwareKeyboard"] = True
            self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)
            self.driver.implicitly_wait(10)
        else:
            self.driver = driver

    # 定义找元素方法
    def find_by_element(self, by, value):
       return self.driver.find_element(by, value)

    # 定义点击事件
    def find_and_click(self, by, value):
        self.driver.find_element(by, value).click()

